<template>
  <d2-container>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <div class="d2-breadcrumb">
        <el-breadcrumb-item>系统管理</el-breadcrumb-item>
        <el-breadcrumb-item>角色管理</el-breadcrumb-item>
        <el-breadcrumb-item>编辑角色详情</el-breadcrumb-item>
      </div>
    </el-breadcrumb>
     <el-form label-width="100px" :model="Info" :rules="rules" ref="add">
      <el-form-item label="角色名称" prop="Name">
        <el-input v-model="Info.Name" style="width: 240px;"></el-input>
      </el-form-item>
      <el-form-item label="角色说明" prop="Remark">
        <el-input type="textarea" v-model="Info.Mobile" style="width: 240px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save">保存</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>
<script>
export default {
  name: "Add-Role",
  data() {
    return {
      Info: {
        Name: "",
        Remark: ""
      },
      rules: {
        Name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
        Remark: [{ required: true, message: "描述不能为空", trigger: "blur" }],
      }
    };
  },
  methods: {
    save() {
      this.$refs["add"].validate(valid => {
        if (valid) {
            let params={
                Name:this.Info.Name,
                Remark:this.Info.Remark
                ,
            }
          this.$axios
            .post("/system/addacc", params)
            .then(result => {
              if (result.data.Code == 200) {
                this.$message.success(result.data.Msg);
                this.$router.push('/')
              } else {
                this.$message.error(result.data.Msg);
              }
            })
            .catch(err => {
              this.$message.error(err);
            });
        } else {
          return false;
        }
      });
    },
    getInfo(){
        let params={
            Id: this.$route.params.id,
        }
        this.$axios.post("/admin/role/info",params).then(result=>{
            if (result.data.Code == 200) {
                this.Info = result.data.Data;
              } else {
                this.$message.error(result.data.Msg);
              }
        })
    }
  },
  created(){
      /**
       * 在页面创建之后，获取详情信息
       * url参数：this.$route.params.id
       */
      this.getInfo()
  }
};
</script>